package cn.edu.scujcc.dpl.ui.dashboard;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import cn.edu.scujcc.dpl.R;
import cn.edu.scujcc.dpl.Trackdebugging;
import cn.edu.scujcc.dpl.createActivity;
import cn.edu.scujcc.dpl.playerActivity;

public class DashboardFragment extends Fragment {

    private DashboardViewModel dashboardViewModel;

        public View onCreateView(@NonNull LayoutInflater inflater,
                                 ViewGroup container, Bundle savedInstanceState) {
            dashboardViewModel =
                    ViewModelProviders.of(this).get(DashboardViewModel.class);
            View root = inflater.inflate(R.layout.fragment_dashboard, container, false);

            Button btn =  root.findViewById(R.id.made_btn);
            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v){
                    Intent it = new Intent();
                    it.setClass(getActivity(), createActivity.class);
                    getActivity().startActivity(it);
                }
            });
            final TextView textView = root.findViewById(R.id.text_dashboard);
            dashboardViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
                @Override
                public void onChanged(@Nullable String s) {
                    textView.setText(s);
                }
            });
            return root;
        }
}